﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.ProductMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-splitter" vertical="true" style="width: 100%; height: 100%;">
        <div size="50%" showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px;" borderstyle="border:0;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            产品编号：<input id="PrdCode" class="mini-textbox" emptytext="请输入产品编号" style="width: 150px;"
                                onenter="onKeyEnter" />
                            产品名称：<input id="PrdName" class="mini-textbox" emptytext="请输入产品名称" style="width: 150px;"
                                onenter="onKeyEnter" />
                            <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a> <a class="mini-button"
                                iconcls="icon-reset" onclick="reset()">重 置</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-toolbar" style="padding: 2px; border-left: 0px; border-right: 0px;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                                class="mini-button" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                            <span class="separator"></span><a class="mini-button" iconcls="icon-freeze" onclick="freeze()"
                                plain="true">禁用</a> <a class="mini-button" iconcls="icon-unfrozen" onclick="unfrozen()"
                                    plain="true">启用</a> <span class="separator"></span><a class="mini-button" onclick="close()"
                                        iconcls="icon-close" plain="true">关闭</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-fit">
                <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="PrdID"
                    selectonload="true" sizelist="[10,20,50,100]" pagesize="20" borderstyle="border:0;"
                    onselectionchanged="onSelectionChanged">
                    <div property="columns">
                        <div type="indexcolumn" width="20">
                        </div>
                        <div field="RecStatus" width="80" headeralign="center" allowsort="true" renderer="onRecStatusRenderer">
                            状态
                        </div>
                        <div field="PrdCode" width="100" headeralign="center" allowsort="true">
                            产品编号
                        </div>
                        <div field="PrdName" width="120" headeralign="center" allowsort="true">
                            产品名称
                        </div>
                        <div field="CheckFile" width="120" headeralign="center" allowsort="true">
                            检验指导书
                        </div>
                        <div field="OpFile" width="120" headeralign="center" allowsort="true">
                            操作指导书
                        </div>
                        <div field="PrdDesc" width="100" headeralign="center" allowsort="true">
                            备注
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div size="50%" showcollapsebutton="true">
            <div class="mini-splitter" vertical="false" style="width: 100%; height: 100%;" borderstyle="border:0;">
                <div size="30%" showcollapsebutton="true">
                    <div id="grid2" class="mini-datagrid" style="width: 100%; height: 100%;" borderstyle="border:0;"
                        showfooter="false" allowresize="true" onselectionchanged="onEqSelectionChanged"
                        idfield="FlowID">
                        <div property="columns">
                            <div type="indexcolumn" width="10%">
                            </div>
                            <div field="ProcessIdx" width="30%" headeralign="center">
                                工序数量
                            </div>
                            <div field="ModelMin" width="60%" headeralign="center">
                                标准换模时间
                            </div>
                        </div>
                    </div>
                </div>
                <div size="70%" showcollapsebutton="true">
                    <div class="mini-splitter" vertical="true" style="width: 100%; height: 100%;" borderstyle="border:0;">
                        <div size="50%" showcollapsebutton="true">
                            <div class="mini-fit">
                                <div id="grid3" class="mini-datagrid" style="width: 100%; height: 100%;" allowresize="true"
                                    showfooter="false" borderstyle="border:0;">
                                    <div property="columns">
                                        <div field="PageNo" width="100%" headeralign="center">
                                            检验指导书显示页数
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div size="50%" showcollapsebutton="true">
                            <div class="mini-fit">
                                <div id="grid4" class="mini-datagrid" style="width: 100%; height: 100%;" allowresize="true"
                                    showfooter="false" borderstyle="border:0;">
                                    <div property="columns">
                                        <div field="PageNo" width="100%" headeralign="center">
                                            作业指导书显示页数
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    mini.parse();
    var grid1 = mini.get("grid1");
    var grid2 = mini.get("grid2");
    var grid3 = mini.get("grid3");
    var grid4 = mini.get("grid4");
    grid1.setUrl("../service/BasicDataManageHandler.ashx?action=GetProductList");
    grid1.load();
    function onSelectionChanged(e) {
        var grid = e.sender;
        var record = grid1.getSelected();
        if (record) {
            $.ajax({
                url: "../Service/BasicDataManageHandler.ashx?action=GetFlowListById&PrdID=" + record.PrdID,
                success: function (text) {
                    var result = mini.decode(text);
                    grid3.clearRows();
                    grid4.clearRows();
                    grid2.clearRows();
                    grid2.addRows(result);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }
        else {
            grid2.setData([]);
        }
    }

    function onEqSelectionChanged(e) {
        var grid = e.sender;
        var record = grid2.getSelected();
        if (record) {
            grid3.clearRows();
            grid3.addRows(record.JyItems);
            grid4.clearRows();
            grid4.addRows(record.ZyItems);
        }
        else {
            grid3.setData([]);
            grid4.setData([]);
        }
    }


    function add() {
        mini.open({
            url: "BasicDataManage/AddProductInfoForm.aspx",
            title: "新增产品", width: 725, height: 570,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid1.reload();
            }
        });
    }

    function edit() {
        var rows = grid1.getSelected();
        if (rows) {
            mini.open({
                url: "BasicDataManage/EditProductInfoForm.aspx",
                title: "编辑产品", width: 725, height: 570,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", PrdID: rows.PrdID };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid1.reload();
                }
            });
        }
        else {
            mini.alert("请选中一条您需要编辑的记录!");
        }
    }

    function freeze() {
        var rows = grid1.getSelected();
        if (rows) {
            if (rows.RecStatus == true) {
                mini.confirm("您确定禁用:" + rows.PrdName + "？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Freeze&table=UT_Product&field=PrdID&value=" + rows.PrdID,
                                success: function (text) {
                                    grid1.reload();
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert(jqXHR.responseText);
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.PrdName + " 当前状态已经是：已禁用!");
            }

        } else {
            mini.alert("请选中一条您需要禁用的记录!");
        }
    }

    function unfrozen() {
        var rows = grid1.getSelected();
        if (rows) {
            if (rows.RecStatus == false) {
                mini.confirm("您确定启用:" + rows.PrdName + "？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Unfrozen&table=UT_Product&field=PrdID&value=" + rows.PrdID,
                                success: function (text) {
                                    grid1.reload();
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert(jqXHR.responseText);
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.PrdName + " 当前状态已经是：已启用!");
            }

        } else {
            mini.alert("请选中一条您需要启用的记录!");
        }
    }

    function search() {
        var PrdCode = mini.get("PrdCode").getValue();
        var PrdName = mini.get("PrdName").getValue();
        grid1.load({ PrdCode: PrdCode, PrdName: PrdName });
    }

    //回车键事件
    function onKeyEnter() {
        search();
    }

    function reset() {
        mini.get("PrdCode").setValue("");
        mini.get("PrdName").setValue("");
    }

    function onRecStatusRenderer(e) {
        if (e.value == "0") { return "<span style=\"color: Red;font-weight:bold;\">已禁用</span>"; }
        else if (e.value == "1") { return "<span style=\"color: Green;font-weight:bold;\">已启用</span>"; }
        else { return ""; }
    }

    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function close() {
        CloseWindow("close");
    }
</script>
